//
//  FFDebugOptionViewController.m
//  FFSurveillance
//
//  Created by roro_latrobe on 16/11/2.
//  Copyright © 2016年 cn.wanda. All rights reserved.
//

#import "FFSDebugOptionViewController.h"
#import "FFLogManager.h"

@interface FFSDebugOptionViewController ()

@end

@implementation FFSDebugOptionViewController

#pragma mark - vc lifeCyle
- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(id)init {
    self = [super init];
    if (self) {
        [self initializeForm];
    }
    return self;
}

//! 代码编写表单 先不支持配置，配置解析还在设计中
- (void)initializeForm {
    XLFormDescriptor * form = [XLFormDescriptor formDescriptorWithTitle:@"飞凡调试选项"];
    form.rowNavigationOptions = XLFormRowNavigationOptionEnabled;
    
    XLFormSectionDescriptor *section;
    XLFormRowDescriptor *row;
    
    //! 构建表单section
    //! 1. 执行环境
    section = [XLFormSectionDescriptor formSectionWithTitle:@"执行环境"];
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_ENV_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"正式环境"];
    row.value = @([GVUserDefaults standardUserDefaults].ffEnvSwitch);
    [section addFormRow:row];
    [form addFormSection:section];
    
    //! 2. 业务过滤
    section = [XLFormSectionDescriptor formSectionWithTitle:@"业务模块"];
    //! beacon
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_BEACON_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"Beacon"];
    row.value = @([GVUserDefaults standardUserDefaults].ffBeaconSwitch);
    [section addFormRow:row];
    //! 交易
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_TRADE_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"交易"];
    row.value = @([GVUserDefaults standardUserDefaults].ffTradgeSwitch);
    [section addFormRow:row];
    //! 一卡通
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_ONECARD_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"一卡通"];
    row.value = @([GVUserDefaults standardUserDefaults].ffOneCardSwitch);
    [section addFormRow:row];
    //! 地图
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_MAP_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"地图"];
    row.value = @([GVUserDefaults standardUserDefaults].ffMapSwitch);
    [section addFormRow:row];
    //! AR
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_AR_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"AR"];
    row.value = @([GVUserDefaults standardUserDefaults].ffARSwitch);
    [section addFormRow:row];
    [form addFormSection:section];
    
    //! 3. 日志关注选项
    section = [XLFormSectionDescriptor formSectionWithTitle:@"日志关注选项"];
    //! API 
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_DEBUG_API_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"API"];
    row.value = @([GVUserDefaults standardUserDefaults].ffDebugAPISwitch);
    [section addFormRow:row];
    //! API Result
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_DEBUG_API_RESULT_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"API Result"];
    row.value = @([GVUserDefaults standardUserDefaults].ffDebugAPIResultSwitch);
    [section addFormRow:row];
    //! h5 地址
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_DEBUG_H5_ADDRESS_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"h5 地址"];
    row.value = @([GVUserDefaults standardUserDefaults].ffDebugH5AddressSwitch);
    [section addFormRow:row];
    //! h5 地址栏
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_DEBUG_H5_SEARCHBAR_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"h5 地址栏"];
    row.value = @([GVUserDefaults standardUserDefaults].ffDebugH5SearchBarSwitch);
    [section addFormRow:row];
    //! 导航逻辑
    row = [XLFormRowDescriptor formRowDescriptorWithTag:FF_DEBUG_NAVIGATOR_FOOTPRINT_SWITCH rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"导航逻辑"];
    row.value = @([GVUserDefaults standardUserDefaults].ffDebugNavigatorFooterPrintSwitch);
    [section addFormRow:row];
    [form addFormSection:section];
    
    //! 把表单描述交给form 去渲染
    self.form = form;
    
}

#pragma mark - XLFormDescriptorDelegate
-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
    [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
    [[GVUserDefaults standardUserDefaults] setValue:newValue forKey:rowDescriptor.tag];
}

@end
